#include "sdopencv/PHaarFeature.hpp"

using namespace std;
using namespace sdopencv;

// swap x and y altogether
PHaarFeature PHaarFeature::swap()
{
    PHaarFeature nf;

    int i, j;
    for(i = 0; i < 2; ++i)
    {
        nf.A[i] = A[i];
        nf.p[i].resize(p[i].size());
        for(j = 0; j < p[i].size(); ++j)
        {
            nf.p[i][j].x = p[i][j].y;
            nf.p[i][j].y = p[i][j].x;
        }
    }

    return nf;
}

// rotate the feature by 90 degrees x -> y -> M-x -> M-y
PHaarFeature PHaarFeature::rotate90(int M)
{
    int i, j;
    PHaarFeature nf;

    for(i = 0; i < 2; ++i)
    {
        nf.A[i] = A[i];
        nf.p[i].resize(p[i].size());
        for(j = 0; j < p[i].size(); ++j)
        {
            nf.p[i][j].x = p[i][j].y;
            nf.p[i][j].y = M - p[i][j].x;
        }
    }

    return nf;
}

// rotate the feature by 180 degrees x -> M-x, y -> M-y
PHaarFeature PHaarFeature::rotate180(int M)
{
    int i, j;
    PHaarFeature nf;

    for(i = 0; i < 2; ++i)
    {
        nf.A[i] = A[i];
        nf.p[i].resize(p[i].size());
        for(j = 0; j < p[i].size(); ++j)
        {
            nf.p[i][j].x = M - p[i][j].x;
            nf.p[i][j].y = M - p[i][j].y;
        }
    }

    return nf;
}

istream& operator >>(istream &is, sdopencv::PHaarFeature &obj)
{
is >> obj.p[0] >> obj.p[1];
is >> obj.A[0] >> obj.A[1];
return is;
}


ostream& operator <<(ostream &os, const sdopencv::PHaarFeature &obj)
{
os << obj.p[0] << obj.p[1];
os << obj.A[0] << " " << obj.A[1] << endl;
return os;
}


